<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title><?php echo ((isset($title) && ($title !== ""))?($title):get_system_config("system_name")); ?></title>
		<link href="/Public/Ins/css/bootstrap.min.css" rel="stylesheet">
		<link href="/Public/Ins/font-awesome/css/font-awesome.css" rel="stylesheet">
		<link href="/Public/Ins/css/animate.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/toastr/toastr.min.css" rel="stylesheet">
		<link href="/Public/Ins/css/plugins/gritter/jquery.gritter.css" />
		<?php if(!empty($plugin["jquery-ui"])): ?><link rel="stylesheet" href="/Public/Ins/css/plugins/jQueryUI/jquery-ui-1.10.4.custom.min.css" />
	<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><?php endif; ?>

	<link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />


		<link href="/Public/Ins/css/style.css" rel="stylesheet">
		<link href="/Public/Ins/css/xiaowei.css" rel="stylesheet">
		<link href="/Public/Ins/css/nprogress.css" rel="stylesheet">
		<script src="/Public/Ins/js/nprogress.js"></script>
		<link rel="stylesheet" href="/Public/Ins/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet"><link rel="stylesheet" href="/Public/Ins/css/plugins/date-time/bootstrap-datetimepicker.css" />
		
	</head>
	<script type="text/javascript">
	var upload_url = "<?php echo U('upload');?>";
	var del_url = "<?php echo U('del_file');?>";
	var app_path = "";
	var cookie_prefix = "<?php echo C('COOKIE_PREFIX');?>";
	var link_select = "<?php echo U('Popup/link_select');?>";
	
</script>

	<body class="<?php echo (CONTROLLER_NAME); ?>">
		<div class="shade"></div>
		<div class="form-group hidden" id="img_upload_container">
			<div id="img_upload">上传</div>
		</div>
		<nav class="navbar navbar-default row" role="navigation" id="top_menu">
			<!-- Brand and toggle get grouped for better mobile display -->
			<div class="navbar-header">
				<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse-6">
					<span class="sr-only">Toggle navigation</span>
					<i class="fa fa-bars fa-lg"></i>
				</button>
				<div class="hidden-xs">
					&nbsp;
				</div>
				<a href="<?php echo U('index/index');?>" class="navbar-brand"><?php echo get_system_config("system_name");?></a>
			</div>
			<!-- Collect the nav links, forms, and other content for toggling -->
			<div class="collapse navbar-collapse" id="navbar-collapse-6">
				<ul class="nav navbar-nav navbar-right">
					<?php if(is_array($top_menu)): foreach($top_menu as $key=>$top_menu_vo): ?><a class="nav-app" href="#" url="<?php echo (get_nav_url($top_menu_vo['url'])); ?>" node="<?php echo ($top_menu_vo["id"]); ?>" onclick="click_top_menu(this)" ><i class="<?php echo ($top_menu_vo["icon"]); ?>"></i><?php echo ($top_menu_vo["name"]); ?>
						<?php if(!empty($badge_count[$top_menu_vo['id']])){ $html=''; $html='<span class="label label-danger">'.$badge_count[$top_menu_vo['id']].'</span>'; echo $html; } ?></a><?php endforeach; endif; ?>
					<a class="nav-app btn-danger" href="<?php echo U('public/logout');?>"><i class="fa fa-sign-out"></i>退出</a>
				</ul>
			</div><!-- /.navbar-collapse -->
		</nav>
		<div id="wrapper">
			<div class="sidebar navbar-static-side" id="sidebar">
				<div id="user_info" class="text-center hidden-xs"  >
					<span >当前用户：<?php echo (session('user_name')); ?></span>
				</div>
				<div id="nav_head" class="text-center" onclick="toggle_left_menu()">
					<span class="menu-text"><?php echo ($top_menu_name); ?></span>
					<b id="left_menu_icon" class="fa fa-angle-down pull-right"></b>
				</div>
				<?php echo W('Sidebar/left',array('tree'=>$left_menu,'badge_count'=>$badge_count));?>
			</div>
			<div id="page-wrapper" class="gray-bg">
				<div class="row wrapper border-bottom gray-bg">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="fa fa-home home-icon"></i>
								<a href="/">Home</a>
							</li>
							<li>
								<?php echo ($top_menu_name); ?>
							</li>
						</ul><!-- .breadcrumb -->
					</div>
				</div>
				<div class="wrapper wrapper-content">
					
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Form</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<link href="/sap/demo.css" rel="stylesheet" type="text/css" />
    <script src="/sap/scripts/boot.js" type="text/javascript"></script>
    

</head>
<body>


    <div id="form1" >
        <input name="id" class="mini-hidden"  value="<?php echo ($data["id"]); ?>"/>
        <table style="width: 700px">
            
            <!-- <tr>
                <td>
                    <label for="textbox1$text">名称：</label>
                </td>
                <td>
                    <input id="textbox1"  name="name" class="mini-textbox" width='250px' required="true"  value ="<?php echo ($data["name"]); ?>"  />
                </td>
            </tr> -->
            
            
            <tr>
                <td>
                    <label for="textbox1$text">选择平台：</label>
                </td>
                <td>
                
    
    			<input id="btnEdit1" class="mini-buttonedit" onbuttonclick="onButtonEdit" style="width: 550px" text="<?php echo ($data["cname"]); ?>" value="<?php echo ($data["code"]); ?>"/>  
                </td>
            </tr>
			
			 <tr>
                <td>
                    <label for="textbox1$text">品牌：</label>
                </td>
                <td>
                    <input id="textbox1"  name="brand_name" class="mini-textbox" required="true" width='250px' value ="<?php echo ($data["brand_name"]); ?>"/>
                </td>
            </tr>
			
			 <tr>
                <td>
                    <label for="textbox1$text">类目：</label>
                </td>
                <td>
                    <input id="textbox1"  name="category" class="mini-textbox" required="true" width='250px'  value ="<?php echo ($data["category"]); ?>"/>
                </td>
            </tr>
			
             <tr>
                <td>
                    <label for="textbox1$text">授权链：</label>
                </td>
                <td >
                <div id='sqlian' style="float: left">
                   <?php for($i=0;$i<$data['level'];$i++){ $auth_chain = $data['auth_chain'][$i]; if($i==$data['level']-1){ echo "<input style='width:90px'  class='mini-textbox authinput' name='auth_chain[$i]' value='$auth_chain'>"; }else{ echo "<input style='width:90px'  class='mini-textbox authinput' name='auth_chain[$i]' value='$auth_chain'>->"; } }?>
					<?php if(count($data['level'])==0){ echo "<input style='width:90px'  class='mini-textbox authinput' name='auth_chain[0]'>"; }?>
					
					
					</div>
					 <a class="mini-button" iconCls="icon-add" style="background: none;border: none;float: left" id='addinput'>
                </td>
            </tr>
			
			
			 <tr>
                <td>
                    <label for="textbox1$text">授权有效期：</label>
                </td>
                <td>
                    <input id="start" name='start' class="mini-datepicker" value="<?php echo ($data["start"]); ?>" valueType='string'  />--<input valueType='string' id="end" name='end' class="mini-datepicker" value="<?php echo ($data["end"]); ?>"/>
                </td>
            </tr>
			
			
			 <tr>
                <td>
                    <label for="textbox1$text">备注：</label>
                </td>
                <td>
                    <input id="textbox1"  name="note" class="mini-textarea" width='250px'  value ="<?php echo ($data["note"]); ?>"/>
                </td>
            </tr>
            
             <tr>
                <td>
                    <label for="textbox1$text">附件：</label>
                </td>
                <td>
	                 <div class="uploader" id="uploader_add_file" add_file_id="add_file">
					 <input id="add_file_add_file" class="add_file"  name="attachment" value="<?php echo ($data["attachment"]); ?>" style="display: none" >
					 <a id="btn_add_file" href="javascript:;" class="">添加附件</a>
					<ul class="file_list" new_upload="" >
				<?php foreach($data['att'] as $att){?>
					<li class="tbody" id="{$att.md5}" add_file="<?php echo ($att["code"]); ?>">
					<div class="loading" style="width: 100%;"></div>
					<div class="data" >
					<span class="del text-center" style='width: 75px'><a class="link del" style="display: inline;">删除</a> <a class="link showpic" data='/Uploads/Download/<?php echo ($att["savepath"]); echo ($att["savename"]); ?>'>查看</a></span>
					<span class="size text-right"><?php echo ($att["size"]); ?> kb</span><span class="auto autocut"><?php echo ($att["name"]); ?></span></div>
					</li>
				<?php }?>
					
					</ul>
				</div> 
                </td>
            </tr>
			
            
			<tr>
                <td>
                    
                </td>
                <td>
				    <br/>
                    <a class='mini-button' onclick="submitForm(1)" >保存</a>
                    <a class='mini-button' onclick="CloseWindow()" >取消</a>
                                                          
                    
                </td>
            </tr>
            
        </table>
    </div>
    <script type="text/javascript">
        mini.parse();
        
        function onButtonEdit(e) {
            var btnEdit = this;

            mini.open({
                url:  "/auth/select",                          
                title: "选择平台",
                width: 650,
                height: 380,
                ondestroy: function (action) {
                  
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);
                        btnEdit.setValue(data.id);
                        btnEdit.setText(data.text);
                    }
                }
            });            
             
        }  
        
    	 function onValueChanged(e) {
             
             var item = e.selected;
             if (item) { 
                 mini.get('cname-show').setValue(item.text);  
             }
         }
    
		jQuery('.showpic').click(function(){
			window.open(jQuery(this).attr('data'));
			
		})
      

        function submitForm(tag) {
			
			var code = mini.get('btnEdit1').getValue();
			var name = mini.get('btnEdit1').getText();
			
            //提交表单数据
            var form = new mini.Form("#form1");            
            var data = form.getData();      //获取表单多个控件的数据
            data.attachment = jQuery('#add_file_add_file').val();
            data.code = code;
            data.cname = name;
            var json = mini.encode(data);   //序列化成JSON
			
           $.ajax({
                url: "/auth/dosave",
                type: "post",
                data: { data: json },
                success: function (text) {
					if(text>0){
						if(tag==0){
							CloseWindow('ok');
						}else{
							mini.alert('保存成功');
						}
						
					}else{
						mini.alert('保存失败...');
					}
                   
                }
            });

        }
     
		
   function CloseWindow(action) {
	      
	   location.href=document.referrer;
    }
   
   
   jQuery('#addinput').click(function(){
	   
	   var authinputlist = jQuery('.authinput');
	   var count =authinputlist.length;

	  var   html ="-><input style='width:90px'  class='mini-textbox authinput' name='auth_chain["+count+"]'>";
	   
	   jQuery('#sqlian').append(html); mini.parse();
	  
	   });
	  
  
   


    </script>
    
    <script type="text/javascript">
    
    $(document).ready(function() {
    	var uploaders = {};
    	$('.uploader').each(function() {
    		var uploader, $target, $id;
    		$target = $(this);
    		$id = $target.attr('add_file_id');
    		$btn_id = 'btn_' + $id;
    		$uploader_id = 'uploader_' + $id;

    		settings = {
    			runtimes : 'html5,flash',
    			browse_button : $btn_id, // you can pass in id...
    			container : document.getElementById($uploader_id),
    			url : upload_url,
    			flash_swf_url : app_path + '/Public/Static/plupload/Moxie.swf',
    			filters : {
    				max_file_size : '1000mb'
    			}
    		};

    		uploader = new plupload.Uploader(settings);
    		uploaders[$id] = uploader;

    		function FilesAdded(up, files) {
    			
    			for (var i in files) {
    				var str = JSON.stringify(files);
    			
    				if( files[i].id!=null){
    				 
    				html = '<li class="tbody" id="' + files[i].id + '">\n';
    				
    				html += '<div class="loading"></div>\n';
    				html += '<div class="data">\n';
    				
    				html += '<span class="del text-center"><a class="link del">删除</a></span>\n';
    				
    				html += '<span class="size text-right">' + plupload.formatSize(files[i].size) + '</span>';
    				html += '<span class="auto autocut">' + files[i].name + '</span>';
    				html += '</li>';
    				html += '</div>\n';
    				
    				$('#uploader_' + $id + ' .file_list').append(html);
    				}
    			}
    			up.start();
    		}

    		uploader.bind("PostInit", function(up) {
    			if ($(".uploader .tbody").length > 0) {
    				$(".uploader .tbody .loading").css("width", "100%");
    				$(".uploader .thead").show();
    				$(".uploader .tbody").each(function() {
    					id = $(this).attr("filename");
    					filename = $(this).attr("filename");
    					size = $(this).attr("size");
    					file = new plupload.File(id, filename, size);
    					file.status = plupload.DONE;
    					count = uploader.files.length;
    					uploader.files[count] = file;
    					path = 'hhhhhhh';
    				});
    			}
    		});

    		uploader.init();

    		uploader.bind('FilesAdded', FilesAdded);

    		uploader.bind("UploadProgress", function(up, file) {
    			$("#" + file.id).find("a.del").hide();
    			$("#" + file.id).find('.loading').css("width", file.percent + "%");
    		});

    		uploader.bind('FileUploaded', function(up, file, data) {
    			var myObject = eval('(' + data.response + ')');
    			if (myObject.status) {
    				if ($("#add_file_" + $id).length != 0) {
    					$("#add_file_" + $id).val($("#add_file_" + $id).val() + myObject.sid + ";");
    				}
    				$("#" + file.id).attr("add_file", myObject.sid);

    				$new_upload = $("#uploader_" + $id + " .file_list").attr("new_upload");
    				$("#uploader_" + $id + " .file_list").attr("new_upload", $new_upload + myObject.sid + ";");

    				$("#" + file.id).find("a.del").show();
    			} else {
    				ui_alert(myObject.info, function() {
    					$("#" + file.id).remove();
    				});
    			}
    		});
    	});
    });

    window.onbeforeunload = function(e) {
    	e = e || window.event;
    	// For IE and Firefox prior to version 4
    	$new_upload = $(".file_list").attr("new_upload");
    	if ($new_upload !== undefined) {
    		if ($new_upload.length) {
    			if (e) {
    				e.returnValue = '上传的附件将被删除，确定退出吗？';
    			}
    			// For Safari
    			return '上传的附件将被删除，确定退出吗？';
    		}
    	}
    };

    $(document).on("click", ".uploader a.del", function() {
    	$obj = $(this).parents("li");
    	$uploader = $(this).parents('.uploader');
    	ui_confirm("确定要删除吗？", function() {

    		$current_del_file = $obj.attr("add_file");
    		$(".add_file", $uploader).val($(".add_file", $uploader).val().replace($current_del_file + ";", ""));

    		$new_upload = $(".file_list", $uploader).attr("new_upload");
    		$(".file_list", $uploader).attr("new_upload", $new_upload.replace($current_del_file + ";", ""));

    		$obj.remove();
    	});
    });
    </script>

</body>
</html>


				</div>
			</div>
		</div>
		<iframe src="<?php echo U('push/client');?>" class="push" id="push"></iframe>
		<!-- Mainly scripts -->
		<script src="/Public/Ins/js/jquery-2.1.1.js"></script>
		<script src="/Public/Ins/js/bootstrap.min.js"></script>
		<script src="/Public/Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
		<script src="/Public/Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		

		<!-- Custom and plugin javascript -->
		<script src="/Public/Ins/js/inspinia.js"></script>
		<script src="/Public/Ins/js/common.js"></script>
		<script src="/Public/Ins/js/plugins/pace/pace.min.js"></script>
		<?php if(!empty($plugin["jquery-ui"])): ?><script src="/Public/Ins/js/plugins/jquery-ui/jquery-ui.min.js"></script>
	<script src="/Public/Ins/js/plugins/nouslider/jquery.nouislider.min.js"></script><?php endif; ?>

	<script src="/Public/Ins/js/plugins/date-time/moment-with-locales.js"></script>
	<script src="/Public/Ins/js/plugins/date-time/bootstrap-datetimepicker.js"></script>


<?php if(!empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script>
	<?php if(empty($plugin["auth"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.setting.js"></script><?php endif; endif; ?>

<?php if(!empty($plugin["editor"])): if(empty($plugin["uploader"])): ?><script type="text/javascript" src="/Public/Ins/js/plugins/plupload/plupload.full.min.js"></script><?php endif; ?>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.min.js"></script>
	<script type="text/javascript" src="/Public/Ins/js/plugins/tinymce/tinymce.setting.js"></script><?php endif; ?>

<?php if(!empty($plugin["baidu_map"])): ?><script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=EE6745c36d96321e90b7015f3de4a4ee"></script><?php endif; ?>

<script src="/Public/Ins/js/plugins/toastr/toastr.min.js"></script>
<script src="/Public/Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
<script src="/Public/Ins/js/plugins/bootbox/bootbox.min.js"></script>

<script type="text/javascript">
	$(document).ready(function() {
		<?php if(!empty($plugin["date"])): ?>$('.input-date').datetimepicker({
			format : 'YYYY-MM-DD',
			locale : 'zh-cn',
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});
		
		$(".input-daterange input").datetimepicker({
			format : "YYYY-MM-DD",
			locale : 'zh-cn',
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});

		$("#start_date").on("dp.change", function(e) {
			if ($("#end_date").length > 0) {
				$('#end_date').data("DateTimePicker").minDate(e.date);
			}
		});
		
		$("#end_date").on("dp.change", function(e) {
			if ($("#start_date").length > 0) {
				$('#start_date').data("DateTimePicker").maxDate(e.date);
			}
		});

		$(".input-date-time").datetimepicker({
			format : 'YYYY-MM-DD HH:mm',
			locale : 'zh-cn',
			sideBySide : true,
			showTodayButton : true,
			showClose : true,
			ignoreReadonly : true,
			widgetPositioning : {
				horizontal : 'auto',
				vertical : 'bottom'
			},
		});<?php endif; ?>		 
	}); 
</script>
		
	<script type="text/javascript">
		function save() {
			sendForm("form_data", "<?php echo U('save');?>", "<?php echo U('index');?>");
		}
	</script>

	</body>
</html>